
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
    #region FriendInfo Model -(by fangyifeng at 2007-09-14 16:51:28)

    /// <summary>
    /// FriendInfo object'FriendInfo'.
    /// </summary>
    [Serializable]
    public class FriendInfo : System.IComparable
    {
        #region Member Variables

        protected Guid _id;
        protected string _relation;
        protected string _name;
        protected int _age;
        protected DateTime _birthday;
        protected string _tel;
        protected string _email;
        protected string _sex;
        protected FriendGroup _friendGroup;
        protected Address _address;

        protected static String _sortExpression = "Id";
        protected static SortDirection _sortDirection = SortDirection.Ascending;

        #endregion

        #region Constructors

        public FriendInfo() { }

        public FriendInfo(string relation, string name, int age, DateTime birthday, string tel, string email, string sex, FriendGroup friendGroup, Address address)
        {
            this._relation = relation;
            this._name = name;
            this._age = age;
            this._birthday = birthday;
            this._tel = tel;
            this._email = email;
            this._sex = sex;
            this._friendGroup = friendGroup;
            this._address = address;
        }

        #endregion

        #region Public Properties

        public virtual Guid Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public virtual string Relation
        {
            get { return _relation; }
            set
            {
                if (value != null && value.Length > 10)
                    throw new ArgumentOutOfRangeException("Invalid value for Relation", value, value.ToString());
                _relation = value;
            }
        }

        public virtual string Name
        {
            get { return _name; }
            set
            {
                if (value != null && value.Length > 50)
                    throw new ArgumentOutOfRangeException("Invalid value for Name", value, value.ToString());
                _name = value;
            }
        }

        public virtual int Age
        {
            get { return _age; }
            set { _age = value; }
        }

        public virtual DateTime Birthday
        {
            get { return _birthday; }
            set { _birthday = value; }
        }

        public virtual string Tel
        {
            get { return _tel; }
            set
            {
                if (value != null && value.Length > 30)
                    throw new ArgumentOutOfRangeException("Invalid value for Tel", value, value.ToString());
                _tel = value;
            }
        }

        public virtual string Email
        {
            get { return _email; }
            set
            {
                if (value != null && value.Length > 80)
                    throw new ArgumentOutOfRangeException("Invalid value for Email", value, value.ToString());
                _email = value;
            }
        }

        public virtual string Sex
        {
            get { return _sex; }
            set
            {
                if (value != null && value.Length > 1)
                    throw new ArgumentOutOfRangeException("Invalid value for Sex", value, value.ToString());
                _sex = value;
            }
        }

        public virtual FriendGroup FriendGroup
        {
            get { return _friendGroup; }
            set { _friendGroup = value; }
        }


        public virtual Address Address
        {
            get { return _address; }
            set { _address = value; }
        }


        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
        #endregion

        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
            if (!(obj is FriendInfo))
                throw new InvalidCastException("This object is not of type FriendInfo");

            int relativeValue;
            switch (SortExpression)
            {
                case "Id":
                    relativeValue = this.Id.CompareTo(((FriendInfo)obj).Id);
                    break;
                case "Relation":
                    relativeValue = this.Relation.CompareTo(((FriendInfo)obj).Relation);
                    break;
                case "Name":
                    relativeValue = (this.Name != null) ? this.Name.CompareTo(((FriendInfo)obj).Name) : -1;
                    break;
                case "Age":
                    relativeValue = (this.Age != null) ? this.Age.CompareTo(((FriendInfo)obj).Age) : -1;
                    break;
                case "Birthday":
                    relativeValue = (this.Birthday != null) ? this.Birthday.CompareTo(((FriendInfo)obj).Birthday) : -1;
                    break;
                case "Tel":
                    relativeValue = (this.Tel != null) ? this.Tel.CompareTo(((FriendInfo)obj).Tel) : -1;
                    break;
                case "Email":
                    relativeValue = (this.Email != null) ? this.Email.CompareTo(((FriendInfo)obj).Email) : -1;
                    break;
                case "Sex":
                    relativeValue = (this.Sex != null) ? this.Sex.CompareTo(((FriendInfo)obj).Sex) : -1;
                    break;
                default:
                    goto case "Id";
            }
            if (FriendInfo.SortDirection == SortDirection.Ascending)
                relativeValue *= -1;
            return relativeValue;
        }
        #endregion
    }

    #endregion
}
